<template>
  <template v-for="item,key in data.atk"> 
    <div class="pvp44eq">
    
      <img class="ava" 
      :src="$cfg.function.ava(item)"
      >
      <!-- 武器 -->
      <el-dropdown trigger="click">
      <div class="pvp44_upeq_shield">
        <img class="click_eq_zw" :src="val.eqdata[val.upeq[key].zw].icon" />
        <div class="upeq_tipspb">{{ val.eqdata[val.upeq[key].zw].name }}</div>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <div class="el-dri">
          <el-dropdown-item @click="val.upeq[key].zw = item2.eqid" v-for="(item2, key2) in val.eq.zw" :label="item.eqid" :value="item.eqid">
            <div class="el_sldiv">
              <div class="eq_card">
                <img :src="`${ val.eqdata[item2.eqid].icon }`"> 
              </div> <span>　{{ val.eqdata[item2.eqid].name }}</span>
          </div>
          </el-dropdown-item>
          </div>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
      <!-- 盾牌 -->
      <el-dropdown trigger="click">
      <div class="pvp44_upeq_shield">
        <img class="click_eq_shield" :src="val.eqdata[val.upeq[key].shield].icon" />
        <div class="upeq_tipspb">{{ val.eqdata[val.upeq[key].shield].name }}</div>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <div class="el-dri">
          <el-dropdown-item @click="val.upeq[key].shield = item2.eqid" v-for="(item2, key2) in val.eq.shield" :label="item.eqid" :value="item.eqid">
            <div class="el_sldiv">
              <div class="eq_dun">
                <img :src="`${ val.eqdata[item2.eqid].icon }`"> 
              </div> <span>　{{ val.eqdata[item2.eqid].name }}</span>
          </div>
          </el-dropdown-item>
          </div>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
      <!-- 首饰 -->
      <el-dropdown trigger="click">
      <div class="pvp44_upeq_shield">
        <template v-if="val.upeq[key].accessory == null">
          <img class="click_eq_accessory" :src="img_accessorynone" />
          <div class="upeq_tipspb">饰品</div>
        </template>
        <tempalte v-else>
          <img class="click_eq_accessory" :src="val.eqdata[val.upeq[key].accessory].icon" />
          <div class="upeq_tipspb">{{ val.eqdata[val.upeq[key].accessory].name }}</div>
        </tempalte>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <div class="el-dri">
          <el-dropdown-item @click="val.upeq[key].accessory = item2.eqid" v-for="(item2, key2) in val.eq.accessory" :label="item.eqid" :value="item.eqid">
            <div class="el_sldiv">
              <div class="eq_ss">
                <img :src="`${ val.eqdata[item2.eqid].icon }`"> 
              </div> <span>　{{ val.eqdata[item2.eqid].name }}</span>
          </div>
          </el-dropdown-item>
          </div>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
    <!-- 周边 -->
      <el-dropdown trigger="click">
      <div class="pvp44_upeq_zb">
        <template v-if="val.upeq[key].zb == null">
          <img class="click_eq_zb" :src="img_zbnone" />
          <div class="upeq_tipspb">周边</div>
        </template>
        <tempalte v-else>
          <img class="click_eq_zb" :src="val.eqdata[val.upeq[key].zb].icon" />
          <div class="upeq_tipspb">{{ val.eqdata[val.upeq[key].zb].name }}</div>
        </tempalte>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <div class="el-dri">
          <el-dropdown-item @click="val.upeq[key].zb = item2.eqid" v-for="(item2, key2) in val.eq.zb" :label="item.eqid" :value="item.eqid">
            <div class="el_sldiv">
              <div class="eq_zb">
                <img :src="`${ val.eqdata[item2.eqid].icon }`"> 
              </div> <span>　{{ val.eqdata[item2.eqid].name }}</span>
          </div>
          </el-dropdown-item>
          </div>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
    <!-- 魔卡1 -->
    <el-dropdown trigger="click">
      <div class="pvp44_upeq_zb">
        <template v-if="val.upeq[key].card1 == null">
          <img class="click_eq_card" :src="img_cardnone" />
          <div class="upeq_tipspb">魔卡1</div>
        </template>
        <tempalte v-else>
          <img class="click_eq_card" :src="val.eqdata[val.upeq[key].card1].icon" />
          <div class="upeq_tipspb">{{ val.eqdata[val.upeq[key].card1].name }}</div>
        </tempalte>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <div class="el-dri">
          <el-dropdown-item @click="val.upeq[key].card1 = item2.eqid" v-for="(item2, key2) in val.eq.card" :label="item.eqid" :value="item.eqid">
            <div class="el_sldiv">
              <div class="eq_card">
                <img :src="`${ val.eqdata[item2.eqid].icon }`"> 
              </div> <span>　{{ val.eqdata[item2.eqid].name }}</span>
          </div>
          </el-dropdown-item>
          </div>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
    <!-- 魔卡2 -->
    <el-dropdown trigger="click">
      <div class="pvp44_upeq_zb">
        <template v-if="val.upeq[key].card2 == null">
          <img class="click_eq_card" :src="img_cardnone" />
          <div class="upeq_tipspb">魔卡2</div>
        </template>
        <tempalte v-else>
          <img class="click_eq_card" :src="val.eqdata[val.upeq[key].card2].icon" />
          <div class="upeq_tipspb">{{ val.eqdata[val.upeq[key].card2].name }}</div>
        </tempalte>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <div class="el-dri">
          <el-dropdown-item @click="val.upeq[key].card2 = item2.eqid" v-for="(item2, key2) in val.eq.card" :label="item.eqid" :value="item.eqid">
            <div class="el_sldiv">
              <div class="eq_card">
                <img :src="`${ val.eqdata[item2.eqid].icon }`"> 
              </div> <span>　{{ val.eqdata[item2.eqid].name }}</span>
          </div>
          </el-dropdown-item>
          </div>
        </el-dropdown-menu>
      </template>
    </el-dropdown>



    </div>
  </template>
  <n-button type="warning" @click="ct.upeq_axios">上传此进攻队装备</n-button>

</template>
<style>
  .tttt{
    border: solid 2px;
    width: 50px;
    height: 55px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
</style>
<script>
import { cfg } from "@/cfg/cfg.js";
import img_zbnone from "@/assets/img/eq/zbnone.png"
import img_cardnone from "@/assets/img/eq/cardnone.png"
import img_accessorynone from "@/assets/img/eq/accessorynone.png"

export default {
  props: {
    val: {
      required: true,
    },
    ct: {
      required: true,
    },
  },
  setup(props) {
    let { ct, val } = props;
    const data = {
      atk: val.postm.data.atk,
      def: val.postm.data.def,
      md5: val.postm.atk_teamid,
    };

    ct.upeq_axios = async () => {
      //val.upeq循环
      for (let key = 0; key < val.upeq.length; key++) {
        const item = val.upeq[key];
        if(item.shield == null){
            cfg.msg.error("未装备盾牌", { duration: 2e3 });
            return false;
          }
          if(item.zw == null){
            cfg.msg.error("未装备专武", { duration: 2e3 });
            return false;
          }
          if(item.card1 == null){
            cfg.msg.error(`角色${key+1}未装备魔卡1`, { duration: 2e3 });
            return false;
          }
          if(item.card2 == null){
            cfg.msg.error(`角色${key+1}未装备魔卡2`, { duration: 2e3 });
            return false;
          }
          if(item.accessory == null){
            cfg.msg.error(`角色${key+1}未装备首饰`, { duration: 2e3 });
            return false;
          }
          if(item.zb == null){
            cfg.msg.error(`角色${key+1}未装备周边`, { duration: 2e3 });
            return false;
          }
      }

      const res = await cfg.axios.get(`${cfg.url}`, {
            params: {
              t: "get/work/up_pvpwork_eq",
              atkteamid: data.md5,
              updata: val.upeq,
              authkey : cfg.user.authkey
            },
          });
      const data2 = res.data;
      if(data2.code == -1){
        cfg.msg.error(data2.msg, { duration: 2e3 });
      }else{
        cfg.msg.info(data2.msg, { duration: 2e3 });
        ct.geteq_axios();
      }
        
    }

    val.upeq = [
      {
        shield: "无盾牌",
        zw : "专武",
        zb : null,
        accessory : null,
        card1 : null,
        card2 : null,
      },{
        shield: "无盾牌",
        zw : "专武",
        zb : null,
        accessory : null,
        card1 : null,
        card2 : null,
      },{
        shield: "无盾牌",
        zw : "专武",
        zb : null,
        accessory : null,
        card1 : null,
        card2 : null,
      },{
        shield: "无盾牌",
        zw : "专武",
        zb : null,
        accessory : null,
        card1 : null,
        card2 : null,
      },
    ];



    return { data, ct, val,img_zbnone,img_cardnone,img_accessorynone };
  },
};
</script>
